local panshi = fk.CreateSkill{
  name = "investiture__panshi",
  tags = { Skill.Hidden },
}

Fk:loadTranslationTable{
  ["investiture__panshi"] = "盘世",
  [":investiture__panshi"] = "隐匿。你登场后，从牌堆获得手牌中缺少花色的牌各一张；"
  .. "一个回合结束时，若中央区内有四种花色和三种类别的牌，你隐匿。",
}

local U = require "packages/utility/utility"
local DIY = require "packages/diy_utility/diy_utility"

panshi:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

panshi:addEffect(U.GeneralAppeared, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasShownSkill(panshi.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = { "diamond", "club", "heart", "spade" }
    for _, id in ipairs(player:getCardIds("h")) do
      local card = Fk:getCardById(id)
      if table.contains(suits, card:getSuitString()) then
        table.removeOne(suits, card:getSuitString())
      end
    end
    local cards = {}
    for _, suit in ipairs(suits) do
      table.insertTableIfNeed(cards, room:getCardsFromPileByRule(".|.|" .. suit, 1, "drawPile"))
    end
    if #cards > 0 then
      room:moveCardTo(cards, Player.Hand, player, fk.ReasonJustMove, panshi.name)
    end
  end,
})

panshi:addEffect(fk.TurnEnd, {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    if player:hasShownSkill(panshi.name) then
      local center = DIY.getCenterCards(player.room)
      local suits, types = {}, {}
      for _, id in ipairs(center) do
        local card = Fk:getCardById(id)
        if card.suit and card.suit ~= Card.NoSuit then
          table.insertIfNeed(suits, card.suit)
        end
        if card.type then
          table.insertIfNeed(types, card.type)
        end
        if #suits == 4 and #types == 3 then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    DIY.enterHidden(player)
  end
})

return panshi